<script type = "text/javascript">
function mypopup(){
 window.open("print.php", "myWindow", "status=0, height=600, width=700, resizable=1, scrollbars=1")
}
</script>
<?php
//=========================================================================================================================================
function listEmployees($sortorder, $value)
{
   global $link;

   if ($sortorder == BYLASTNAME)
   {
      $sql .= " order by a.LastName, a.FirstName, a.LastName";
      print '<font color="black" size=5> List of Employees by Last Name</font><br><br>';
   }
   elseif ($sortorder == BYID)
   {
      $sql .= " order by a.HostUserID";
      print '<font color="black" size=5> List of Employees by ID</font><br><br>';
   }
   else
   {
      $sql .= " order by b.HostDescription";
      print '<font color="black" size=5> List of Employees by Host Description</font><br><br>';
   }

   $result=mysql_query($sql,$link);

   $formshow  = '<TABLE BORDER="1"><TR>';
   $formshow .= '<TD width="36"><font color="green">ID#</font></TD>';
   $formshow .= '<TD width="36"><font color="green">Employee#</font></TD>';
   $formshow .= '<TD width="270"><font color="green">Employee Name</font></TD>';

   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      if (strlen($data["Suffix"]) > 0)
      {
         $fullname  = $data["LastName"].' '.$data["Suffix"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }
      else
      {
         $fullname  = $data["LastName"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }

      $formshow .= '<TR><TD><font face="arial" color="black" size=2>'.$data["HostUserID"].'<font></TD>';
	  $formshow .= '<TD><font face="arial" color="black" size=2>'.$data["SignatureID"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="black" size=2>'.$fullname.'<font></TD>';
      $formshow .= '<TD><font face="arial" color="black" size=2>'.$data["HostDescription"].'<font></TD></TR>';
   }

   $formshow .= '</TABLE>';
   $formshow .= '<BR><BR><FONT color="red">Total No. of Employees Listed: '.mysql_num_rows($result).'</font></br>';
   if($value == 2) {
	      $formshow .= '<table>			
				<tr>
				<td align="right" width=650><font size="2" face="MS Sans Serif"><img src="images/printlogo.png" height="20" width="20"><a style="color:#909090" href="javascript:window.print()">print this page</font></a></></td>
				</tr>
				</table>';}   

   if($value == 1){		  
		  $formshow .= '<table>			
				<tr>
				<td align="right" width=650><font size="2" face="MS Sans Serif"><img src="images/printlogo.png" height="20" width="20"><form><input type="button" onClick="mypopup()" value="Click To Print"></form></></td>
				</tr>
				</table>';}

   print $formshow;
}
//=========================================================================================================================================

function listAllEmployeeActivity($department, $fromdatepicker, $todatepicker)
{
   global $link;
   global $mintime;
   global $maxtime;

   $header = TRUE;

   while(//fetch data from mysql))
   {
      if ($department == IT)
      {
         if (in_array($data["HostUserID"], $itservices))
         {
            listEmployeeActivity($data["HostUserID"], $fromdatepicker, $todatepicker, TRUE, $header);
            $header = FALSE;
         }
      }
      else
      {
         if (!in_array($data["HostUserID"], $itservices))
         {
            listEmployeeActivity($data["HostUserID"], $fromdatepicker, $todatepicker, TRUE, $header);
            $header = FALSE;
         }
      }
   }

   $formshow  = '</TABLE>';
   
   print $formshow;
}
//=========================================================================================================================================
function listEmployeeActivity($hostid, $fromdatepicker, $todatepicker, $all, $header)
{
   global $link;
   global $mintime;
   global $maxtime;

   if (strlen($data["Suffix"]) > 0)
   {
      $fullname  = $data["LastName"].' '.$data["Suffix"].', '.$data["FirstName"].' '.$data["MiddleName"];
   }
   else
   {
      $fullname  = $data["LastName"].', '.$data["FirstName"].' '.$data["MiddleName"];
   }

   $hostCardStamp = $data["HostCardStamp"];
   $formshow  = '';

   if (!$all)
   {
      $formshow .= '<font color="black" size=5>'.$fullname.'</font><BR><BR><BR>';
   }

   if ($header)
   {
      $formshow .= '<TABLE BORDER="1" align=center><TR>';

      if ($all)
      {
         $formshow .= '<TD width="300"><font color="green">Employee Name</font></TD>';
      }
      $formshow .= '<TD width="100"><font color="green">Date</font></TD>';
      $formshow .= '<TD width="100"><font color="green">Time In</font></TD>';
      $formshow .= '<TD width="100"><font color="green">Time Out</font></TD>';
   }

   //print $fromdatepicker.' '.$todatepicker;
   $fromdate = convertDatePicker($fromdatepicker,"YYYYMMDD");
   $fromdatebin = strtotime($fromdate);
   
   $todate   = convertDatePicker($todatepicker,"YYYYMMDD");
   $todatebin = strtotime($todate);
   $temp     = '';

   $credentialid = getCredentialIDFromDB($hostid);

   if (strlen($credentialid) > 0)
   {
      for ($i=0; $fromdatebin <= $todatebin; $i++)
      {
         $nextdate  = substr(add_date($fromdate, 1,0,0),0,10);

         getTimeEntryExit($hostid, $credentialid, $fromdate, $nextdate, $hostCardStamp, TRUE);

         if ($all)
         {
            $formshow .= '<TR><TD width="200"><font face="arial" color="green">'.$fullname.'</font></TD>';
            $fullname  = '';
         }
         else
         {
            $formshow .= '<TR>';
         }
         
         $formshow .= '<TD align="center"><font face="arial" color="black" size=2>'.$fromdate.'</font></TD>';
         $formshow .= '<TD align="center"><font face="arial" color="black" size=2>'.$mintime.'</font></TD>';
         $formshow .= '<TD align="center"><font face="arial" color="black" size=2>'.$maxtime.'</font></TD>';

         if ($mintime != NULL)
         { 
            $formshow .= '<TD align="center"><font face="arial" color="black" size=2>'.date_diff1($mintime, $maxtime).'</font></TD></TR>';
         }
         else
         {
            $formshow .= '<TD align="center"><font face="arial" color="black" size=2></font></TD></TR>';
         }

         //print $fromdate;
         $fromdate  = $nextdate;
         $fromdatebin = strtotime($fromdate);
      }
   }

   if (!$all)
   {
      $formshow .= '</TABLE></br>';
	      $formshow .= '<table>			
<tr>
<td align="right" width=650><font size="2" face="MS Sans Serif"><img src="images/printlogo.png" height="20" width="20"><a style="color:#909090" href="javascript:window.print()">print this page</font></a></></td>
</tr>
</table>';
   }
  
   print $formshow;
}

//=========================================================================================================================================
function EmployeeListFromDBToSelect_ID()
{
   global $link;

   $select = "";

   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      if (strlen($data["Suffix"]) > 0)
      {
         $fullname  = $data["LastName"].' '.$data["Suffix"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }
      else
      {
         $fullname  = $data["LastName"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }
 
      $select .= '<option value="'.$data["HostUserID"].'">';
      $select .= $data["HostUserID"].' - '.$fullname.'</option>';
   }

   return($select);
}
//=========================================================================================================================================
function EmployeeListFromDBToSelect()
{
   global $link;

   $select = "";

   while(//fetch data from mysql)
   {
      if (strlen($data["Suffix"]) > 0)
      {
         $fullname  = $data["LastName"].' '.$data["Suffix"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }
      else
      {
         $fullname  = $data["LastName"].', '.$data["FirstName"].' '.$data["MiddleName"];
      }
      
      $select .= '<option value="'.$data["HostUserID"].'">';
      $select .= $fullname.' - '.$data["HostUserID"].'</option>';
   }

   return($select);
}


?>
